<%@ page pageEncoding="utf-8" %>
<%@include file="/commons/taglibs.jsp" %>
<!DOCTYPE html>
<html>
<fmt:bundle basename="res">
<head>
    <meta charset="utf-8">
    <title><fmt:message key='lb' /></title>
    <jsp:include page="/WEB-INF/commons/commons-header.jsp" flush="true"/>
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">

            <div class="layui-form-item">
                <form name="totalForm" id="totalForm" action="${web_domain}/merchant/coupon/list" method="get">

                    <div class="layui-inline">
                        <label class="layui-form-label"><fmt:message key='yhjmc' /></label>
                        <div class="layui-input-inline">
                            <input type="text" name="name" placeholder="<fmt:message key='qsryhjmc' />" value="<c:if test='${params.name !=null}'>${params.name}</c:if>" autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label"><fmt:message key='yhjlx' /></label>
                        <div class="layui-input-inline">
                            <select lay-verify="required" lay-filter="topChannel" name="type">
                                <option value="0" <c:if test="${params.type eq 0}">selected="selected"</c:if>><fmt:message key='qxz' /></option>
                                <option value="1" <c:if test="${params.type eq 1}">selected="selected" </c:if>><fmt:message key='mjj' /></option>
                                <option value="2" <c:if test="${params.type eq 2}">selected="selected"</c:if>><fmt:message key='zpj' /></option>
                            </select>
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label"><fmt:message key='yhjzt' /></label>
                        <div class="layui-input-inline">
                            <select lay-verify="required" name="status">
                                <option value="0" <c:if test="${params.status eq 0}">selected="selected"</c:if>><fmt:message key='qxz' /></option>
                                <option value="1" <c:if test="${params.status eq 1}">selected="selected"</c:if>><fmt:message key='dshenh' /></option>
                                <option value="2" <c:if test="${params.status eq 2}">selected="selected"</c:if>><fmt:message key='shtg' /></option>
                                <option value="3" <c:if test="${params.status eq 3}">selected="selected"</c:if>><fmt:message key='shbtg' /></option>
                                <option value="4" <c:if test="${params.status eq 4}">selected="selected"</c:if>><fmt:message key='shz' /></option>
                                <option value="5" <c:if test="${params.status eq 5}">selected="selected"</c:if>><fmt:message key='ylw' /></option>
                            </select>
                        </div>
                    </div>

                    <!-- 需要排序的字段 -->
                    <%--<input type="hidden" class="feijin-orderby" name="orderByCreateTime" id="orderByCreateTimeParams" value="${params.orderByCreateTime}"/>--%>
                    <%--<input type="hidden" class="feijin-orderby" name="orderByStore" id="orderByStoreParams" value="${params.orderByStore}"/>--%>
                    <%--<input type="hidden" class="feijin-orderby" name="orderByPrice" id="orderByPriceParams" value="${params.orderByPrice}"/>--%>
                    <%--<input type="hidden" class="feijin-orderby" name="orderBySalesVolume" id="orderBySalesVolumeParams" value="${params.orderBySalesVolume}"/>--%>
                    <!-- 需要排序的字段 -->
                    <input type="hidden" name="status" value="${params.status}"/>

                    <div class="layui-inline">
                        <button class="layui-btn layui-btn-sm layuiadmin-btn-list" id="search"><i class="layui-icon layui-icon-search layuiadmin-button-btn"></i> <fmt:message key='ss' /></button>
                    </div>
                </form>
            </div>
        </div>

    </div>

    <div class="layui-card">
        <div class="layui-field-box layui-form">

            <a href="javascript:void(0);" class="layui-btn layui-btn-sm layui-btn-normal" id="add"><i class="layui-icon">&#xe61f;</i> <fmt:message key='tj' /></a>

            <a href="javascript:void(0);" class="layui-btn layui-btn-sm layui-btn-warm" id="putaways"><i class="layui-icon">&#xe605;</i> <fmt:message key='plsqsj' /></a>

            <a href="javascript:void(0);" class="layui-btn layui-btn-sm layui-btn-danger" id="soldouts"><i class="layui-icon">&#x1006;</i> <fmt:message key='plxj' /></a>


            <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
                <ul class="layui-tab-title">
                    <li
                            <c:if test="${params.status eq 0}">class="layui-this"</c:if> >
                        <a href="${web_domain}/merchant/coupon/list"
                           <c:if test="${params.status eq 0}">style="color: rgb(0, 150, 136)"</c:if> ><fmt:message key='qb' /></a>
                    </li>
                    <li <c:if test="${params.status eq 1}">class="layui-this"</c:if>>
                        <a href="${web_domain}/merchant/coupon/list?status=1" <c:if test="${params.status eq 1}">style="color: rgb(0, 150, 136)"</c:if>><fmt:message key='dshenh' /></a>
                    </li>
                    <li <c:if test="${params.status eq 4}">class="layui-this"</c:if>>
                        <a href="${web_domain}/merchant/coupon/list?status=4" <c:if test="${params.status eq 4}">style="color: rgb(0, 150, 136)"</c:if>><fmt:message key='shz' /></a>
                    </li>
                    <li <c:if test="${params.status eq 2}">class="layui-this"</c:if>>
                        <a href="${web_domain}/merchant/coupon/list?status=2" <c:if test="${params.status eq 2}">style="color: rgb(0, 150, 136)"</c:if>><fmt:message key='shtg' /></a>
                    </li>
                    <li <c:if test="${params.status eq 3}">class="layui-this"</c:if>>
                        <a href="${web_domain}/merchant/coupon/list?status=3" <c:if test="${params.status eq 3}">style="color: rgb(0, 150, 136)"</c:if>><fmt:message key='shbtg' /></a>
                    </li>
                </ul>
            </div>


            <table class="layui-table" lay-size="sm">
                <thead>
                <th width="5%"><input id="checkboxs" type="checkbox" lay-ignore lay-skin="primary"/></th>
                <th><fmt:message key='yhjmc' /></th>
                <th><fmt:message key='yhjlx' /></th>
                <th><fmt:message key='sysp' /></th>
                <th><fmt:message key='mkje' /></th>
                <th><fmt:message key='mz' /></th>
                <th><fmt:message key='zpsp' /></th>
                <th><fmt:message key='ffsl' /></th>
                <th><fmt:message key='yxq' /></th>
                <th><fmt:message key='cjsj' /></th>
                <th><fmt:message key='zt' /></th>
                <th><fmt:message key='sfsj' /></th>
                <th><fmt:message key='cz' /></th>
                </thead>
                <c:forEach items="${page.result}" var="item" varStatus="status">
                    <tr>
                        <td>
                            <c:if test="${item.status != 3}">
                                <input type="checkbox" value="${item.id}" class="feijin-check" lay-ignore lay-skin="primary"/>
                            </c:if>
                        </td>
                        <td>${item.name }</td>
                        <td>
                            <c:choose>
                                <c:when test="${item.type eq 1}"><fmt:message key='mjj' /></c:when>
                                <c:when test="${item.type eq 2}"><fmt:message key='zpj' /></c:when>
                            </c:choose>
                        </td>
                        <td>
                            <c:choose>
                                <c:when test="${item.scopeType eq 1}"><fmt:message key='qbspky' /></c:when>
                                <c:when test="${item.scopeType eq 2}"><fmt:message key='zdsp' /></c:when>
                            </c:choose>
                        </td>
                        <td><fmt:formatNumber value="${item.conditionAmount}" type="CURRENCY"/></td>
                        <td><fmt:formatNumber value="${item.denominationAmount}" type="CURRENCY"/></td>
                        <td>${item.complimentaryGoods.name}</td>
                        <td>${item.releasedQuantity}</td>

                        <td>
                            <c:choose>
                                <c:when test="${item.validityType eq 1}">
                                    ${item.validityBeginDay} - ${item.validityEndDay}
                                </c:when>
                                <c:when test="${item.validityType eq 2}"><fmt:message key='lqh' />${item.validityDay}<fmt:message key='tnky' /></c:when>
                            </c:choose>
                        </td>
                        <td><fmt:formatDate value="${item.createTime}" pattern="yyyy-MM-dd HH:ss"/></td>
                        <td>
                            <c:choose>
                                <c:when test="${item.status eq 1}"><fmt:message key='dshenh' /></c:when>
                                <c:when test="${item.status eq 2}"><fmt:message key='shtg' /></c:when>
                                <c:when test="${item.status eq 3}"><fmt:message key='shbtg' /></c:when>
                                <c:when test="${item.status eq 4}"><fmt:message key='shz' /></c:when>
                            </c:choose>
                        </td>
                        <td>
                            <c:choose>
                                <c:when test="${item.publishStatus eq 1}"><fmt:message key='xj' /></c:when>
                                <c:when test="${item.publishStatus eq 2}"><fmt:message key='shj' /></c:when>
                            </c:choose>
                        </td>
                        <td>
                            <div class="layui-btn-container">

                                <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-xs feijin-detail"><fmt:message key='ck' /></a>

                                <c:if test="${item.status eq 3}">
                                    <a href="javascript:void(0);" data-checkNote="${item.note}" class="layui-btn layui-btn-normal layui-btn-xs feijin-checkNote"><fmt:message key='ckyy' /></a>
                                </c:if>

                                <c:if test="${item.status eq 1}">
                                    <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-xs feijin-modify"><fmt:message key='bj' /></a>
                                    <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-danger layui-btn-xs feijin-remove"><fmt:message key='sc' /></a>
                                    <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-normal layui-btn-xs feijin-apply-process"><fmt:message key='tjsh' /></a>
                                </c:if>

                                <c:if test="${item.status eq 2}">
                                    <c:choose>
                                        <c:when test="${item.publishStatus eq 1}">
                                            <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-normal layui-btn-xs feijin-putaway"><fmt:message key='shj' /></a>
                                        </c:when>
                                        <c:otherwise>
                                            <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-danger layui-btn-xs feijin-soldout"><fmt:message key='xj' /></a>
                                        </c:otherwise>
                                    </c:choose>
                                </c:if>

                                <c:if test="${item.status == 2 || item.status == 5}">
                                    <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-xs feijin-record"><fmt:message key='lqjl' /></a>
                                </c:if>

                            </div>
                        </td>
                    </tr>
                </c:forEach>
            </table>
            <jsp:include page="/commons/page.jsp" flush="true"/>
        </div>
    </div>

</div>

<script>

    $(function () {

        //全选反选
        $("#checkboxs").click(function () {
            if (this.checked) {
                $(".feijin-check:checkbox").prop("checked", true);
            } else {
                $(".feijin-check:checkbox").prop("checked", false);
            }
        });


        //批量申请上架
        $("#putaways").click(function () {
            var ids = [];

            $(".feijin-check:checkbox:checked").each(function (index, item) {
                var id = $(item).val();
                ids.push(id);
            });

            if (ids.length == 0) {
                layer.msg('<fmt:message key='qxgxxyczdjl' />');
                return false;
            }

            layer.open({
                content: '<fmt:message key='qrsjqbyhj' />'
                , btn: ['<fmt:message key='sqsj' />', '<fmt:message key='qx' />']
                , yes: function (index, layero) {
                    $.ajax({
                        url: "${web_domain}/merchant/coupon/applysPutaway",
                        type: "post",
                        dataType: "json",
                        data: {
                            "ids": ids.join(";"),
                            "_method": "put"
                        },
                        success: function (result) {
                            if (result.status) {
                                location.reload();
                            }
                        }
                    });
                }
            });
        });

        //批量下架
        $("#soldouts").click(function () {
            var ids = [];

            $(".feijin-check:checkbox:checked").each(function (index, item) {
                var id = $(item).val();
                ids.push(id);
            });

            if (ids.length == 0) {
                layer.msg('<fmt:message key='qxgxxyczdjl' />');
                return false;
            }

            layer.open({
                content: '<fmt:message key='qrxjqbyhj' />'
                , btn: ['<fmt:message key='xj' />', '<fmt:message key='qx' />']
                , yes: function (index, layero) {
                    $.ajax({
                        url: "${web_domain}/merchant/coupon/soldoutss",
                        type: "post",
                        dataType: "json",
                        data: {
                            "ids": ids.join(";"),
                            "_method": "put"
                        },
                        success: function (result) {
                            if (result.status) {
                                location.reload();
                            }
                        }
                    });
                }
            });
        });


        //查看详情
        $(".feijin-detail").click(function () {

            var id = $(this).attr("data-id");

            layer.open({
                type: 2
                , title: '<fmt:message key='ckxq' />'
                , content: '${web_domain}/merchant/coupon/' + id + '/detail'
                , maxmin: true
                , area: ['97%', '97%']
                , btn: ['<fmt:message key='fh' />']
            });
        });


        //申请审核
        $(".feijin-apply-process").click(function () {
            var id = $(this).attr("data-id");
            layer.confirm("<fmt:message key='qrshyhj' />", function () {
                feijin.put({
                    url: "${web_domain}/merchant/coupon/applyProcess",
                    data: {id: id}
                });
            });
        });

        $(".feijin-checkNote").click(function () {
            var checkNote = $(this).attr("data-checkNote");
            layui.use('layer', function () {
                layer.msg(checkNote);
            });
        });

        //上架优惠券
        $(".feijin-putaway").click(function () {
            var id = $(this).attr("data-id");
            layer.confirm("<fmt:message key='qrsjyhj' />", function () {
                feijin.put({
                    url: "${web_domain}/merchant/coupon/applyPutaway",
                    data: {id: id}
                });
            });
        });

        //下架优惠券
        $(".feijin-soldout").click(function () {
            var id = $(this).attr("data-id");
            layer.confirm("<fmt:message key='qrxjyhj' />", function () {
                feijin.put({
                    url: "${web_domain}/merchant/coupon/soldout",
                    data: {id: id}
                });
            });
        });

        //添加优惠券
        $("#add").click(function () {
            layer.open({
                type: 2
                , title: '<fmt:message key='tjyhj' />'
                , content: '${web_domain}/merchant/coupon/create'
                , maxmin: true
                , area: ['97%', '97%']
                , btn: ['<fmt:message key='bc' />', '<fmt:message key='qx' />']
                , yes: function (index, layero) {
                    var submit = layero.find('iframe').contents().find("#submit");
                    submit.click();
                }
            });
        });

        //编辑
        $(".feijin-modify").click(function () {

            var id = $(this).attr("data-id");

            layer.open({
                type: 2
                , title: '<fmt:message key='bjyhj' />'
                , content: '${web_domain}/merchant/coupon/' + id + '/modify'
                , maxmin: true
                , area: ['97%', '97%']
                , btn: ['<fmt:message key='bc' />', '<fmt:message key='qx' />']
                , yes: function (index, layero) {
                    var submit = layero.find('iframe').contents().find("#submit");
                    submit.click();
                }
            });
        });


        //删除优惠券
        $(".feijin-remove").click(function () {
            var id = $(this).attr("data-id");
            layui.use('layer', function () {
                var layer = layui.layer;
                layer.open({
                    type: 0,
                    title: '<fmt:message key='scyhj' />',
                    border: [0],
                    content: '<span class="orange"><fmt:message key='scczyhj' /></span>',
                    btn: ['删除', '取消'],
                    yes: function () {
                        $.ajax({
                            type: "post",
                            url: "${web_domain}/merchant/coupon/remove",
                            dataType: "json",
                            data: {
                                "id": id,
                                "_method": "delete"
                            },
                            success: function (data) {
                                location.reload();
                            }
                        });
                    },
                    no: function () {
                        layer.close(index);
                    }
                });
            });
        });

        //领取记录
        $(".feijin-record").click(function () {
            var id = $(this).attr("data-id");
            layer.open({
                type: 2
                , title: '<fmt:message key='lqjl' />'
                , content: '${web_domain}/merchant/coupon/' + id + '/recordList'
                , maxmin: true
                , area: ['90%', '90%']
                , btn: ['<fmt:message key='fh' />']
            });
        });

    });
</script>
</body>
</fmt:bundle>
</html>
